package history.double_exam;
// 1. dp[i] 为是否能跳到当前i的下标
// 2. dp[i] = dp[i-maxJump]...dp[i-minJump]
public class LeetCode_5765 {
    public static void main(String[] args) {
        System.out.println(canReach("00111010", 3, 5));
    }

    public static boolean canReach(String s, int minJump, int maxJump) {
        if (s == null || s.length() == 0) return false;
        int length = s.length();
        if (length == 1) return s.charAt(0) == '0' ? true : false;
        if (!s.contains("1")) return true;
        if (s.charAt(0) == '1' || s.charAt(length - 1) == '1') return false;
        char[] charArray = s.toCharArray();
        boolean[] state = new boolean[s.length()];
        state[0] = s.charAt(0) == '0' ? true : false;
        for (int i = 0; i < length; i++) {
            if (charArray[i] == '1') state[i] = false;
        }

        for (int i = 0; i < length; i++) {
            if (state[i] == true) {
                for (int j = i + maxJump; j >= i + minJump; j--) {
                    if (j >= length) continue;
                    if (j == length - 1) {
                        for (int k = 0; k < length; k++) {
                            System.out.println(String.format("state[%s] is : %s", k, state[k]));
                        }
                        return true;
                    }
                    if (charArray[j] == '0') {
                        state[j] = true;
                    }
                }
            }
        }
        for (int i = 0; i < length; i++) {
            System.out.println(String.format("state[%s] is : %s", i, state[i]));
        }
        return state[length - 1];
    }
}
